local xinlao = fk.CreateSkill {
  name = "cf_xinlao",
  tags = { Skill.Compulsory, },
}

Fk:loadTranslationTable {
  ["cf_xinlao"] = "辛劳",
  [":cf_xinlao"] = "锁定技，结束阶段，你摸两张牌，然后选择一项，1.重铸任意张牌然后回复一点体力；2.失去一点体力，执行一个额外的出牌阶段。背水：跳过你的下个摸牌阶段。",
  ["#cf_xinlao_choice1"] = "重铸任意张牌然后回复一点体力",
  ["#cf_xinlao_choice2"] = "失去一点体力，执行一个额外的出牌阶段",
  ["#cf_xinlao_choice3"] = "背水：跳过你的下个摸牌阶段",
  ["#cf_xinlao_recast"] = "重铸任意张牌",
  ["@@cf_xinlao"] = "跳过摸牌",
}

xinlao:addEffect(fk.EventPhaseStart, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xinlao.name) and player.phase == Player.Finish
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, xinlao.name)
    local chioce = room:askToChoice(player, {
      choices = { "#cf_xinlao_choice1", "#cf_xinlao_choice2", "#cf_xinlao_choice3" },
      skill_name = xinlao.name,
      cancelable = false,
    })
    event:setCostData(self, { chioce = chioce })
    return true
  end,
  on_use = function(self, event, target, player, data)
    local choice = event:getCostData(self).chioce
    local room = player.room
    if choice == "#cf_xinlao_choice3" then
      room:addPlayerMark(player, "@@" .. xinlao.name)
    end
    if choice == "#cf_xinlao_choice1" or choice == "#cf_xinlao_choice3" then
      local cards = room:askToCards(player, {
        min_num = 1,
        max_num = 999,
        skill_name = xinlao.name,
        cancelable = true,
        include_equip = true,
        prompt = "#cf_xinlao_recast"
      })
      room:recover {
        num = 1,
        who = player,
        skillName = xinlao.name,
        recoverBy = player,
      }
      if #cards > 0 then room:recastCard(cards, player) end
    end
    if choice == "#cf_xinlao_choice2" or choice == "#cf_xinlao_choice3" then
      room:loseHp(player, 1, xinlao.name)
      player:gainAnExtraPhase(Player.Play, xinlao.name)
    end
  end
})

xinlao:addEffect(fk.EventPhaseChanging, {
  can_refresh = function(self, event, target, player, data)
    return target == player and player:getMark("@@" .. xinlao.name) > 0 and data.phase == Player.Draw and
        not data.skipped
  end,
  on_refresh = function(self, event, target, player, data)
    data.skipped = true
    local room = player.room
    room:setPlayerMark(player, "@@" .. xinlao.name, 0)
  end,
})

return xinlao
